package com.itheima.tcp.fileupload.demo2;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //创建用户端socket对象
        Socket socket = new Socket("127.0.0.1",10000);
        try {
            //通过socket对象获取网络输出流
            OutputStream outputStream = socket.getOutputStream();
            //创建本地输入对象，读取本地文件
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\itcast\\mn.jpg"));
            byte[] bytes = new byte[1024];
            int len;

            while ((len = bis.read(bytes)) != -1){
                outputStream.write(bytes,0,len);
            }
            bis.close();
            socket.shutdownOutput();

            //接收服务器反馈数据
            InputStream inputStream = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String msg;
            while ((msg = br.readLine()) != null){
                System.out.println(msg);
            }
            socket.close();


        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
